package cn.javaxc.mvcwork.controller;
import cn.javaxc.mvcwork.util.common.StringUtils;


public class SubmenuItem {

  String name = "";
  String longHtml = "";
  String shortHtml = "";
  String alternateName = "";
  String link = "";
  String htmlClass = "submenuItemUnselected";
  String permission = "";
	String label = "";

  String graphicWidth = "";
  String graphicHeight = "";
  String graphicOn = "";
  String graphicOff = "";
  String graphicRollover = "";

  boolean isActive = false;
  
  private boolean isDashboard = false;
  private boolean isCustomTab = false;


  
  public SubmenuItem() {
  }


  
  public SubmenuItem(SubmenuItem otherItem) {
    this.setName(new String(otherItem.getName()));
    this.setLongHtml(new String(otherItem.getLongHtml()));
    this.setShortHtml(new String(otherItem.getShortHtml()));
    this.setAlternateName(new String(otherItem.getAlternateName()));
    this.setLink(new String(otherItem.getLink()));
    this.setHtmlClass(new String(otherItem.getHtmlClass()));
    this.setPermission(new String(otherItem.getPermission()));

    this.setGraphicOn(new String(otherItem.getGraphicOn()));
    this.setGraphicOff(new String(otherItem.getGraphicOff()));
    this.setGraphicRollover(new String(otherItem.getGraphicRollover()));
    this.setGraphicWidth(new String(otherItem.getGraphicRollover()));
    this.setGraphicHeight(new String(otherItem.getGraphicRollover()));
  }


  
  public boolean getIsActive() {
    return isActive;
  }


  
  public void setIsActive(boolean isActive) {
    this.isActive = isActive;
  }


  
  public void setName(String tmp) {
    this.name = tmp;
  }


  
  public String getGraphicWidth() {
    return graphicWidth;
  }


  
  public String getGraphicHeight() {
    return graphicHeight;
  }


  
  public String getGraphicOn() {
    return graphicOn;
  }


  
  public String getGraphicOff() {
    return graphicOff;
  }


  
  public String getGraphicRollover() {
    return graphicRollover;
  }


  
  public void setGraphicWidth(String tmp) {
    this.graphicWidth = tmp;
  }


  
  public void setGraphicHeight(String tmp) {
    this.graphicHeight = tmp;
  }


  
  public void setGraphicOn(String tmp) {
    this.graphicOn = tmp;
  }


  
  public void setGraphicOff(String tmp) {
    this.graphicOff = tmp;
  }


  
  public void setGraphicRollover(String tmp) {
    this.graphicRollover = tmp;
  }


  
  public void setLongHtml(String tmp) {
    this.longHtml = tmp;
  }


  
  public void setShortHtml(String tmp) {
    this.shortHtml = tmp;
  }


  
  public void setAlternateName(String tmp) {
    this.alternateName = tmp;
  }


  
  public void setLink(String tmp) {
    this.link = tmp;
  }


  
  public void setHtmlClass(String tmp) {
    this.htmlClass = tmp;
  }


  
  public void setPermission(String tmp) {
    this.permission = tmp;
  }

public void setLabel(String tmp) { this.label = tmp; }

  
  public String getHtml() {
    if (link == null || link.equals("")) {
      return longHtml;
    } else {
      return ("<a " + (htmlClass.equals("") ? "" : "class='" + htmlClass + "' ") +
          "href='" + link + "'>" + longHtml + "</a>");
    }
  }


  
  public String getLongHtml() {
    return longHtml;
  }


  
  public String getShortHtml() {
    return shortHtml;
  }


  
  public String getAlternateHtml(SystemStatus systemStatus) {
    String value = systemStatus.getSubMenuProperty(shortHtml);
    if (value == null) {
      value = shortHtml;
    }
    if (link == null || link.equals("")) {
      return StringUtils.toHtml(value);
    } else {
      if (!value.startsWith("&nbsp;")) {
        return ("<a " + (htmlClass.equals("") ? "" : "class='" + htmlClass + "' ") +
            "href='" + link + "'>" + StringUtils.toHtml(value) + "</a>");
      } else {
        int count = 0;
        while (value.startsWith("&nbsp;")) {
          ++count;
          value = value.substring(6);
        }
        return (addSpace(count) + "<a " + (htmlClass.equals("") ? "" : "class='" + htmlClass + "' ") +
            "href='" + link + "'>" + StringUtils.toHtml(value) + "</a>");
      }
    }
  }


  
  private String addSpace(int count) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < count; i++) {
      sb.append("&nbsp;");
    }
    return sb.toString();
  }


  
  public String getImageHtml() {
    if (link == null || link.equals("")) {
      return shortHtml;
    } else {
      return ("<a href='" + link + "'><img name='" + shortHtml + "' src='images/common/" + ((isActive) ? graphicOn : graphicOff) + "' border=0 onMouseOut=\"MM_swapImgRestore()\" onMouseOver=\"MM_swapImage('" + shortHtml + "','','images/common/" + graphicRollover + "',1)\"></a>");
    }
  }


  
  public String getName() {
    return name;
  }


  
  public String getAlternateName() {
    return alternateName;
  }


  
  public String getLink() {
    return link;
  }


  
  public String getHtmlClass() {
    return htmlClass;
  }


  
  public String getPermission() {
    return permission;
  }


  
  public boolean hasPermission(String thisPermission) {
    return (permission.equals(thisPermission));
  }
public String getLabel() { return label; }


	
	public boolean isCustomTab() {
		return isCustomTab;
	}


	
	public void setCustomTab(boolean isCustomTab) {
		this.isCustomTab = isCustomTab;
	}


	
	public boolean isDashboard() {
		return isDashboard;
	}


	
	public void setDashboard(boolean isDashboard) {
		this.isDashboard = isDashboard;
	}

}
